package gemini.castor.ui.client.mvp.callback;

import com.google.gwt.user.client.rpc.AsyncCallback;

import gemini.castor.ui.client.mvp.gin.CastorGinjector;
import gemini.castor.ui.client.page.RootEvent;
import gemini.castor.ui.client.page.widget.dialog.GmnDialog;
import gemini.castor.ui.client.page.widget.dialog.GmnDialog.GmnDialogType;
import gemini.castor.ui.client.page.widget.dialog.GmnDialogEvent;
import gemini.castor.ui.client.page.widget.dialog.GmnDialogHandler;




public abstract class AbstractAsyncCallback<T> implements AsyncCallback<T> {

    /**
     * {@inheritDoc}
     */
    @Override
    public void onFailure(final Throwable caught) {
    	CastorGinjector.INSTANCE.getEventBus().fireEvent(new RootEvent(
				RootEvent.ForwardType.UN_MASK));
    	String message = caught.getMessage();

		GmnDialog dlgConfirm = new GmnDialog(GmnDialogType.ERROR,
				"System Error", 
				message, 
				"OK");

		dlgConfirm.addConfirmationHandler(new GmnDialogHandler() {

			@Override
			public void onOK(GmnDialogEvent event) {
				CastorGinjector.INSTANCE.getRootPresenter().currentScreen();
			}

			@Override
			public void onCancel(GmnDialogEvent event) {
				
			}
		});

		dlgConfirm.show();
    }
}
